//
//  UploadVideoCell.m
//  CloudTest
//
//  Created by 张帅 on 2020/7/27.
//  Copyright © 2020 张帅. All rights reserved.
//

#import "UploadVideoCell.h"
@interface UploadVideoCell ()
@property(nonatomic,strong)UIView * baseView;
@property(nonatomic,strong)UILabel * showLabel;
@property (nonatomic, strong) UIProgressView *progressView;
@property(nonatomic,strong)QMUIButton * progressStateBtn;
@property(nonatomic,strong)QMUIButton * upload_btn; //重新上传
@end
@implementation UploadVideoCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier  {
    self=[super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = color(@"#F5F5F5");
        [self uiSet];
    }
    return self;
}
- (void)uiSet {
    self.baseView = [[UIView alloc] initWithFrame:CGRectMake(15, 10, SCREEN_WIDTH-30, 80)];
    self.baseView.backgroundColor=[UIColor whiteColor];
    self.baseView.layer.cornerRadius=6;
    self.baseView.layer.masksToBounds=YES;
    [self.contentView addSubview:self.baseView];
    [self addViews];
   
}
- (UIProgressView *)progressView {
    if (_progressView==nil) {
        _progressView = [[UIProgressView alloc] initWithFrame:CGRectMake(0, self.baseView.height-4, self.baseView.width, 4)];
        [_progressView setTrackTintColor:[UIColor colorWithWhite:1.0f alpha:0.0f]];
        [_progressView setTintColor:theme_color];
    }
    return _progressView;
}
- (void)addViews {
    self.progressStateBtn = [UIFactory create_btnWithTitle:@"上传中 %%20" imageName:nil backgroundColor:nil TypefaceColor:color(@"#73000000") fontSize:11 target:nil action:nil];
    self.progressStateBtn.imagePosition = QMUIButtonImagePositionLeft;// 将图片位置改为在文字上方
    self.progressStateBtn.spacingBetweenImageAndTitle = 5;
    [self.progressStateBtn setImage:UIImageMake(@"icon_上传错误_16_nor") forState:UIControlStateSelected];
    [self.baseView addSubview:self.progressStateBtn];
    [self.progressStateBtn mas_updateConstraints:^(MASConstraintMaker *make) {
         make.centerY.mas_equalTo(self.baseView);
         make.right.mas_equalTo(self.baseView.mas_right).offset(-15);
         make.width.mas_equalTo(70);
       }];
    
//    标题
    self.showLabel = [UIFactory create_LabelContent:@"分组A:曲目A" textColor:nil fontSize:15];
    [self.baseView addSubview:self.showLabel];
    [self.baseView addSubview:self.progressView];
    [self.showLabel mas_updateConstraints:^(MASConstraintMaker *make) {
          make.centerY.mas_equalTo(self.baseView);
          make.left.mas_equalTo(15);
          make.right.mas_equalTo(self.baseView.mas_right).offset(-15-70);
      }];
    
    
    self.upload_btn = [UIFactory create_btnWithTitle:@"上传失败" imageName:@"上传错误icon" backgroundColor:nil TypefaceColor:color(@"#FF4C40") fontSize:12 target:self action:nil];
    self.upload_btn.imagePosition= QMUIButtonImagePositionLeft;//
    self.upload_btn.spacingBetweenImageAndTitle = 6;
    [self.baseView addSubview:self.upload_btn];
    [self.upload_btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.baseView);
        make.right.mas_equalTo(self.baseView.mas_right).offset(-12);
        make.height.mas_equalTo(28);
    }];
  
}

- (void)setModel:(VideoModel *)model {
    _model=model;
    self.showLabel.text=_model.name;
    self.progress=_model.progress;
    if (_model.showType==Cell_show_Uploading_type ) {//上传中
           [self.progressView setTintColor:theme_color];
           CGFloat progress =_model.progress * 100;
           NSString * title = [NSString stringWithFormat:@"上传%0.0f%%",progress];
           [self.progressStateBtn setTitle:title forState:UIControlStateNormal];
           self.progressStateBtn.selected=NO;
       } else if (_model.showType==Cell_show_Upload_complete_type) {//完成
           [self.progressView setTintColor:color(@"#2EE6B1")];
           [self.progressStateBtn setTitle:@"上传完成" forState:UIControlStateNormal];
           self.progressStateBtn.selected=NO;
       } else if (_model.showType==Cell_show_Upload_error_type) {//错误
           [self.progressView setTintColor:[UIColor whiteColor]];
//           [self.progressStateBtn setTitle:@"上传错误" forState:UIControlStateNormal];
           self.progressStateBtn.selected=YES;
       }
    
    if (_model.showType==Cell_show_Upload_error_type) {//上传错误
        self.progressStateBtn.hidden = YES;
        self.upload_btn.hidden = NO;
    } else {
        self.progressStateBtn.hidden = NO;
        self.upload_btn.hidden = YES;
    }
    _model.cellHeight=90;
}




- (void)setProgress:(CGFloat)progress {
    _progress=progress;
    self.progressView.progress=_progress;
}

@end
